/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package izsla.beans;

import izsla.entities.SearchCriteria;
import izsla.entities.Trip;
import izsla.entities.TripUser;
import izsla.sb.TripManagementLocal;
import java.util.List;
import javax.ejb.EJB;
import javax.faces.context.FacesContext;

/**
 *
 * @author aki
 */
public class Trips {
    // REQ6

    @EJB
    private TripManagementLocal tm;
    private SearchCriteria searchSettings = new SearchCriteria();
    private int deleteId;

    public Trips() {
    }

    public List<Trip> getTrips() {
        List<Trip> trips = tm.getTrips(searchSettings);
        System.out.println("Number of trips: " + trips.size());
        return trips;
    }

    public SearchCriteria getSearchSetting() {
        return searchSettings;
    }

    public String search() {
        return "search";
    }

    public int getDeleteId() {
        return deleteId;
    }

    public void setDeleteId(int deleteId) {
        this.deleteId = deleteId;
    }

    public String onDeleteTrip() {
        Trip trip = tm.getTrip(deleteId);
        tm.deleteTrip(trip);
        return null;
    }

    // REQ16
    public boolean getIsAdmin() {
        TripUser user = (TripUser)FacesContext.getCurrentInstance().getExternalContext().getSessionMap().get("user");

	return user.getIsAdmin();
    }

}
